/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InventoryPanel.java
 *
 * Created on 03-mars-2009, 22:28:13
 */

package GUI;
import Model.ClockEvent;
import Model.ClockListener;
import Model.InventoryEvent;
import Model.InventoryListener;
import Model.ItemDroppedEvent;
import Model.ItemUsedEvent;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

/**
 *
 * @author Snowangelic
 */
public class InventoryPanel extends javax.swing.JPanel implements InventoryListener,ClockListener {

    EnigmaGUIMainWindow mainInterface;

    Boolean inventoryLayerUpdateNeeded;
    BufferedImage backgroundLayer;
    BufferedImage inventoryLayer;
    BufferedImage clockLayer;

    /** Creates new form InventoryPanel */
    public InventoryPanel() {
        initComponents();

        inventoryLayerUpdateNeeded=true;
        backgroundLayer=EnigmaUtils.ImageLoader.loadImage("./images/inventory.png");

        this.setSize(640,64);
        this.setVisible(true);
    }

    public void setMainWindow(EnigmaGUIMainWindow e){
        mainInterface=e;
    }

    public void setInventoryLayer(BufferedImage img) {
        this.inventoryLayer=img;
        inventoryLayerUpdateNeeded=false;
    }

    @Override
    public void paintComponent(Graphics g){

        //if(inventoryLayerUpdateNeeded)mainInterface.updateInventoryLayer();

        super.paintComponent(g);

        BufferedImage bufferImage = new BufferedImage(640, 64, BufferedImage.TYPE_INT_ARGB);
        Graphics buffer = bufferImage.getGraphics();
        buffer.drawImage(backgroundLayer, 0, 0, null);
        buffer.drawImage(inventoryLayer,0,0,null);
        buffer.drawImage(clockLayer,0,0,null);
        g.drawImage(bufferImage, 0, 0, this);

        repaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setMaximumSize(new java.awt.Dimension(640, 64));
        setMinimumSize(new java.awt.Dimension(640, 64));
        setPreferredSize(new java.awt.Dimension(640, 64));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 640, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 64, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    public void inventoryUpdated(InventoryEvent e) {
        inventoryLayer=e.getSource().getImage();
    }

    public void itemDropped(ItemDroppedEvent e) {
    }

    public void itemUsed(ItemUsedEvent e) {
    }

    public void clockUpdated(ClockEvent e) {
        clockLayer=e.getSource().getImage();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
